package com.goktech.mapper;

import com.goktech.entity.Admin;
import com.goktech.service.AdminService;
import com.goktech.util.javaUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/**
 * @ClassName testAdminMapper
 * @Description TODO
 * @Author 邱华英
 * @Date 2022/10/3 10:53
 * @Version 1.0
 */

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class testAdminMapper {

//    SqlSession session = null;
//    AdminMapper adminMapper = null;
//
//    @Before
//    public void before() throws IOException {
//        session = SqlSessionUtil.getSqlSession();
//        adminMapper = session.getMapper(AdminMapper.class);
//    }
//
//    @After
//    public void after(){
//        session.close();
//    }
//
//    @Test
//    public void testfindByAdmin(){
//        Admin a = new Admin();
//        a.setAzhanghao("123");
//        a.setApassword("123");
//        System.out.println(adminMapper.findByAdmin(a));
//    }

    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private AdminService adminService;

    @Test
    public void testUpdate() throws NoSuchAlgorithmException {
        Admin admin = new Admin();
        admin.setAzhanghao("123");
        admin.setApassword(javaUtil.getResult("123456"));
        adminMapper.insertAdmin(admin);
//        String str = "123";
//        byte[] bytes = javaUtil.encryMD5(str.getBytes());
//        String encoded = Base64.getEncoder().encodeToString(bytes);
//
//        byZhanghao.setApassword(encoded);
//        System.out.println(adminMapper.updateAdmin(byZhanghao));
//
//        Admin byZhanghao1 = adminMapper.findByZhanghao(byZhanghao);
//        String apassword = byZhanghao1.getApassword();
//        System.out.println(apassword.equals(encoded));
//        String str = "123";
//        String str1 = "123";
//        byte[] bytes = javaUtil.encryMD5(str.getBytes());
//        byte[] bytes1 = javaUtil.encryMD5(str1.getBytes());
//        String encoded = Base64.getEncoder().encodeToString(bytes);
//        String encoded1 = Base64.getEncoder().encodeToString(bytes1);
//        System.out.println(encoded.equals(encoded1));
//        System.out.println(bytes);
    }
}
